import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/pin_order";

export const create_order_api = (data: any, showError = true) => {
  return Http.post<{ order_id: string }>(
    `/v3${baseUrl}/create_order`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const mini_pay_api = (data: { order_id: string }, showError = true) => {
  return Http.post<any>(`/v3${baseUrl}/mini_pay`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
